#include "temu.h"
#include <stdlib.h>

CPU_state cpu;

const char *reg_file[] = {"$zero", "$ra", "$tp", "$sp", "$a0", "$a1", "$a2", "$a3", "$a4", "$a5", "$a6", "$a7", "$t0",
                          "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8", "$x", "$fp", "$s0", "$s1", "$s2",
                          "$s3", "$s4", "$s5", "$s6", "$s7", "$s8"};

void display_reg() {
    printf("%s\t\t%s\t\t%s\n", "Name", "Hexadecimal", "Decimal");
    int i;
    for (i = 0; i < 32; i++) {
        printf("%s\t\t0x%08x\t\t%d\n", reg_file[i], cpu.gpr[i]._32, cpu.gpr[i]._32);
    }

    printf("%s\t\t0x%08x\t\t%d\n", "$pc", cpu.pc, cpu.pc);
    printf("\n");

}

int name_to_index(char *name) {
    if (strcmp(name, "$zero") == 0)   return 0;
    else if (strcmp(name, "$ra") == 0)return 1;
    else if (strcmp(name, "$tp") == 0)return 2;
    else if (strcmp(name, "$sp") == 0)return 3;
    else if (strcmp(name, "$a0") == 0)return 4;
    else if (strcmp(name, "$a1") == 0)return 5;
    else if (strcmp(name, "$a2") == 0)return 6;
    else if (strcmp(name, "$a3") == 0)return 7;
    else if (strcmp(name, "$a4") == 0)return 8;
    else if (strcmp(name, "$a5") == 0)return 9;
    else if (strcmp(name, "$a6") == 0)return 10;
    else if (strcmp(name, "$a7") == 0)return 11;
    else if (strcmp(name, "$t0") == 0)return 12;
    else if (strcmp(name, "$t1") == 0)return 13;
    else if (strcmp(name, "$t2") == 0)return 14;
    else if (strcmp(name, "$t3") == 0)return 15;
    else if (strcmp(name, "$t4") == 0)return 16;
    else if (strcmp(name, "$t5") == 0)return 17;
    else if (strcmp(name, "$t6") == 0)return 18;
    else if (strcmp(name, "$t7") == 0)return 19;
    else if (strcmp(name, "$t8") == 0)return 20;
    else if (strcmp(name, "$x") == 0) return 21;
    else if (strcmp(name, "$fp") == 0)return 22;
    else if (strcmp(name, "$s0") == 0)return 23;
    else if (strcmp(name, "$s1") == 0)return 24;
    else if (strcmp(name, "$s2") == 0)return 25;
    else if (strcmp(name, "$s3") == 0)return 26;
    else if (strcmp(name, "$s4") == 0)return 27;
    else if (strcmp(name, "$s5") == 0)return 28;
    else if (strcmp(name, "$s6") == 0)return 29;
    else if (strcmp(name, "$s7") == 0)return 30;
    else if (strcmp(name, "$s8") == 0)return 31;
    return -1;
}